package com.chalk.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.chalk.common.util.Result;
import com.chalk.exception.ColumnNotEmptyException;
import com.chalk.model.Coach;
import com.chalk.model.Picture;
import com.chalk.service.CoachService;
import com.chalk.vo.VenueVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author glq
 * @since 2020-12-21
 */

@RestController
@RequestMapping("/v1/coach")
public class CoachController {


    @Autowired
    private CoachService coachService;

    /**
     * @Author 86130
     * @Description //todo 教练分页查询
     * @methodName getCoachForPage
     * @param map:传入页码信息
     * @return Result
     * @Date  2021/9/27 18:54
     **/
    @GetMapping("getCoachForPage")
    public Result getCoachForPage(@RequestParam Map<String, Object> map) throws ColumnNotEmptyException {
        Page<Coach> pictureForPage = coachService.getCoachForPage(map);
        return Result.success(pictureForPage);
    }


    /**
     * @param coach: 教练对象
     * @return Result
     * @Author 86130
     * @Description //todo 新增教练
     * @methodName savePicture
     * @Date 2021/9/26 11:46
     **/
    @PostMapping("saveCoach")
    public Result saveCoach(@RequestBody Coach coach) {
        System.out.println("coach为：" + coach.toString());
        boolean f = coachService.addCoach(coach);
        //return Result.fail("操作失败");
        return f ? Result.success("操作成功") : Result.fail("操作失败");
    }

    /**
     * @Author 86130
     * @Description //todo 修改教练
     * @methodName updateVenue
     * @param coach:
     * @return Result
     * @Date  2021/9/27 19:16
     **/
    @PostMapping("updateCoach")
    public Result updateVenue(@RequestBody Coach coach) {
        int i = coachService.updateCoach(coach);
        return i>0? Result.success("操作成功！") : Result.fail("操作失败");
    }

   /**
    * @Author 86130
    * @Description //todo 逻辑删除教练信息
    * @methodName delete
    * @param ids: 教练ID_S
    * @return Result
    * @Date  2021/9/27 18:55
    **/
    @ApiOperation(value = "批量删除教练表", notes = "批量删除教练表", response = Result.class)
    @DeleteMapping
    public Result delete(
            @ApiParam(name = "ids", value = "传数组", required = true)
            @RequestBody String[] ids) {
        return Result.success(coachService.deleteBatchByPrimaryKey(ids));
    }


}

